﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OABackground.Services;
using SchoolOA.Models;

namespace SchoolOA.Controllers
{
    public class JSController : Controller
    {   
        /// <summary>
        /// 显示教师信息
        /// </summary>
        /// <returns></returns>
        public IActionResult Index(/*string Tid*/)   
        {
            string name = HttpContext.Session.GetString("username");
            string section = HttpContext.Session.GetString("section");
            if (name == null || !section.Equals("js"))
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var teacherService = new TeacherInformationService();
            var teacherInfo = teacherService.QueryTeacherById(name);
            ViewData["teacherName"] = teacherInfo.Tname;
            return View(teacherInfo);
        }

        public IActionResult AwardPunish()
        {
            string name = HttpContext.Session.GetString("username");
            string section = HttpContext.Session.GetString("section");
            if (name == null || !section.Equals("js"))
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var teacherService = new TeacherInformationService();
            var teacherInfo = teacherService.QueryTeacherById(name);
            ViewData["teacherName"] = teacherInfo.Tname;
            return View();
        }

        public IActionResult Convention()
        {
            string name = HttpContext.Session.GetString("username");
            string section = HttpContext.Session.GetString("section");
            if (name == null || !section.Equals("js"))
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var teacherService = new TeacherInformationService();
            var teacherInfo = teacherService.QueryTeacherById(name);
            ViewData["teacherName"] = teacherInfo.Tname;
            return View(teacherInfo);
        }

        public IActionResult Goods()
        {
            string name = HttpContext.Session.GetString("username");
            string section = HttpContext.Session.GetString("section");
            if (name == null || !section.Equals("js"))
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var teacherService = new TeacherInformationService();
            var teacherInfo = teacherService.QueryTeacherById(name);
            ViewData["teacherName"] = teacherInfo.Tname;
            return View(teacherInfo);

        }
        public IActionResult PersonWage()
        {
            string name = HttpContext.Session.GetString("username");
            string section = HttpContext.Session.GetString("section");
            if (name == null || !section.Equals("js"))
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var teacherService = new TeacherInformationService();
            var teacherInfo = teacherService.QueryTeacherById(name);
            ViewData["teacherName"] = teacherInfo.Tname;
            ViewData["time"] = DateTime.Now.ToString("yyyy")+'/'+ DateTime.Now.ToString("MM") + "/01";
            return View(teacherInfo);
        }
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
